import { Texture2D, Vec2 } from 'cc';

class RenderContentData {
    private static _inst: RenderContentData;
    private width: number = 0;
    private height: number = 0;
    static get I(): RenderContentData {
        if (!this._inst) this._inst = new RenderContentData();
        return this._inst;
    }
    pixelData: Uint8Array;
    init(width: number, height: number) {
        this.width = width;
        this.height = height;
        this.pixelData = new Uint8Array(width * height * 4).fill(0);
    }
  getBuffer(){
    return this.pixelData;
  }
  arrayDataFusion(data: ArrayLike<number>) {
    if (!this.pixelData) return false;
    const len = Math.min(this.pixelData.length, data.length);
    for (let i = 0; i < len; i++) {
      let v = data[i] as number;
      if (v > 255) v = v / 255;
      if (v < 0) v = 0;
      if (v > 255) v = 255;
      this.pixelData[i] = Math.round(v);
    }
    return true;
  }
}

export default RenderContentData;
export { RenderContentData };